import pandas as pd
from typing import List, Dict, Set


class ProductInfo:
    def __init__(self, activity_id=None, product_id=None, url=None):
        self.activity_id = activity_id
        self.product_id = product_id
        self.url = url


def getProductsIds() -> Set[int]:
    raw_str = "3715596548902617351, 3716486631407092140, 3716486075368210452, 3716486045253107796, 3716486990154301501, 3716486745383108769, 3716303644417720757, 3716303025984373198, 3716303504730620171, 3716303322404225508, 3716303803281178922, 3716304082470830423, 3716304217795854581, 3716304275752747087, 3716303693902118963, 3716303449080594910, 3716303848428667131, 3716303463936819639, 3716304086891626700, 3716303919362736171, 3716145976260558874, 3716143764276904352, 3715972465940365394, 3716145935391261055, 3717215277046431770, 3716145087059722676, 3715971607014015278, 3716145847243767866, 3716145376995180894, 3716145462986801215, 3716146102844653674, 3716144561068835071, 3716145299819987138, 3716145890386378912, 3714274270289986028, 3716486163381485672, 3715973174719021214, 3715971855996289173, 3715970971283358042, 3715973307644903497, 3715972397254443205, 3715970898310857056, 3715750768419143826, 3715751086255112624, 3715751118257652045, 3715751958133473358, 3715597135283093585, 3715596660689207490, 3715596173042647350, 3715595217546641807, 3715595567552922085, 3715596220429894054, 3715595878971605174, 3715595140279173404, 3715596484402610296, 3715595550331109799, 3715596042088087937, 3715595316305723834, 3715595994851836264, 3715596130059419781, 3715596057154027715, 3715596308342505710, 3715596712061043009, 3717214907536638411, 3717214003555074413, 3715594938323435990, 3715596248389124277, 3715595872453656837, 3716856977872257034, 3716856887795384409, 3716856694471524396, 3716856969349431350, 3716857184139739595, 3716856127544230074, 3716856550573342864, 3716856580688445552, 3716856338039570581, 3716856726608281795, 3716708638300176479, 3716708045737296049, 3716706598358483839, 3716707465799270696, 3716706544570728931, 3716707908138958958, 3716708490107027531, 3716707815797162447, 3717014755827908840, 3717014622667145335, 3717014747019870411, 3717351852585648223, 3717352524848693512, 3717352007321911380, 3717353184008732761, 3717351805508780443, 3717258993396220371, 3717014764375900243, 3717353113183715455, 3715223608419811359, 3705533127154860042, 3717012200297202160, 3715751058128110396, 3715751979465703431, 3715595168179683737, 3715595775808504237, 3716486326456025492, 3716486337403158775, 3717164778960060477, 3717163501089849588, 3717162887094075815, 3717165695893635434, 3717163743940051307, 3717164942202372580, 3717165960134787398, 3717389755713978499, 3717388948327235906, 3717389826555773716, 3717389566727029147, 3717390086485180571, 3717390960594911301, 3717389622536437930, 3717594992999530834, 3717595547041923285, 3717594705228333286, 3717595321438699973, 3717595484622291024, 3717594688056852808, 3717595272105296353, 3717595458995093794, 3717595877569855886, 3717595566318944379, 3717595538485543354, 3717594498910519795, 3717596283444265075, 3717595334390710565, 3717595957119025452, 3717594939262107928, 3717595697239949371, 3717595628663079316, 3717595471888384393, 3717595869021864177, 3717595209819881685, 3717596337307517268, 3717596053839675693, 3717596070918881493, 3717595725291454784, 3717595710175183087, 3717595375067070776, 3717596408082202626, 3717596388805181465, 3717785917021356331, 3717786748231745785, 3717787250600312864, 3717774567654162573, 3717787239963557979, 3717786389568422222, 3717786370232680673, 3717785393035346292, 3717786703067480269, 3717786524868280600, 3717990039720951911, 3717989565101900039, 3717989719712334279, 3717989492129399281, 3717989822791549681, 3717989702540853403, 3717989943159685282, 3717989672476082587, 3717990065406869568, 3717989801358655879, 3717989492129399283, 3718340985684623775, 3718340382333993376, 3718339705843089838, 3718340502517579968, 3718341404628484209, 3718340418874769703, 3718341385309519909, 3718339471750595034, 3718340809783902690, 3718344685798949320, 3718340919179739356, 3718345894966460426, 3718515045743853742, 3718514736439099791, 3718515619264593920, 3718514199769514197, 3718515187611992096, 3718513424351756787, 3718514311254114611, 3718723796321042658, 3718724251470135472, 3718723967993905531, 3718725868458213601, 3718724661715009575, 3718724861430989108, 3718723967993905609, 3718723673847365987, 3718724481250885704, 3718725071817277455, 3718725151349670047"

    # 去除每个元素的前后空格，并过滤掉空字符串
    cleaned_items = (item.strip() for item in raw_str.split(","))
    filtered_items = filter(None, cleaned_items)  # 过滤掉空字符串
    return set(map(int, filtered_items))


def get_products(file_path: str) -> Dict[str, ProductInfo]:
    # 读取Excel文件
    df = pd.read_excel(file_path, sheet_name=0, skiprows=0)

    # 将DataFrame转换为ProductInfo对象列表
    products = []
    for _, row in df.iterrows():
        product = ProductInfo(
            activity_id=row['activity_id'],
            product_id=row['product_id'],
            url=row['url']
        )
        products.append(product)

    # 将ProductInfo对象列表转换为字典，键为product_id
    product_dict = {product.product_id: product for product in products}
    return product_dict


def generateProducts() -> List[ProductInfo]:
    add_list = []
    product_ids = getProductsIds()
    products_map = get_products("/Users/libin/product.xlsx")

    for product_id in product_ids:
        product_info = products_map.get(product_id)
        if product_info is None:
            continue
        item = ProductInfo()
        item.product_id = product_id
        item.url = product_info.url
        add_list.append(item)

    return add_list


# # 示例调用
# products = generateProducts()
# for product in products:
#     print(f"Product ID: {product.product_id}, URL: {product.url}")
